package com.miku.ai.controller;

import cn.hutool.core.io.FileUtil;
import com.miku.ai.common.BaseResponse;
import com.miku.ai.common.ErrorCode;
import com.miku.ai.common.ResultUtils;
import com.miku.ai.exception.BusinessException;
import com.miku.ai.exception.ThrowUtils;
import com.miku.ai.mapper.UserAnswerMapper;
import com.miku.ai.model.dto.file.UploadFileRequest;
import com.miku.ai.model.entity.User;
import com.miku.ai.model.enums.FileUploadBizEnum;
import com.miku.ai.model.statistic.AppAnswerCountDto;
import com.miku.ai.model.statistic.AppAnswerResultCountDto;
import com.miku.ai.service.UserService;
import com.miku.ai.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * App统计接口
 */
@RestController
@RequestMapping("/app/statistic")
@Slf4j
public class AppStatisticController {
    @Resource
    private UserAnswerMapper userAnswerMapper;

    /**
     * 获取用户回答数
     * @return
     */
    @GetMapping("/appAnswerCount")
    public BaseResponse<List<AppAnswerCountDto>> getAppAnswerCount(){
        return ResultUtils.success(userAnswerMapper.doAppAnswerCount());
    }

    /**
     * 获取用户回答结果数
     * @param appId
     * @return
     */
    @GetMapping("/appAnswerResultCount")
    public BaseResponse<List<AppAnswerResultCountDto>> getAppAnswerResultCount(@RequestParam Long appId){
        ThrowUtils.throwIf(appId == null || appId <= 0, ErrorCode.PARAMS_ERROR);
        return ResultUtils.success(userAnswerMapper.doAppAnswerResultCount(appId));
    }
}
